<?php

namespace app\common\model\api;

use think\Model;

class Friend extends Model
{

    protected $table = 'api_friend';

    public function isFriend($uid, $fid)
    {
        $u = $this -> where(['uid'=>$uid,'fid'=>$fid,'status'=>1])->find();
        $f = $this -> where(['uid'=>$fid,'fid'=>$uid,'status'=>1])->find();
        return !empty($u) && !empty($f);
    }

    public function fundByUserName($username)
    {
        return $this->where('username', $username)->find();
    }

    public function fundByUserNameWithStatus($username)
    {
        return $this->where('username', $username)->where('status', 1)->find();
    }

    public function updateLoginInfo($data)
    {
        $result = $this->fundByUserNameWithStatus($data['username']);
        return $result->allowField(['last_login_token'])->save($data);
    }
}
